package demo.mq.rocket.vo;

import com.alibaba.fastjson.JSON;
import demo.java.time.DateTimeDemo;

import java.time.LocalDateTime;

/**
 * 队列统计信息
 * 
 * @author junying.han
 *
 */
public class QueueStatInfo {
    /** 所属 broker */
    private String brokerName;
    /** 队列ID */
    private Integer queueId;
    /** broker上的偏移量 */
    private Integer brokerOffset;
    /** 消费到的偏移量 */
    private Integer consumerOffset;
    /** 消费客户端信息，如：10.21.85.244@77 */
    private String clientInfo;
    /** 最后消费时间 */
    private Long lastTimestamp;

    public LocalDateTime getLastTime() {
        if (this.lastTimestamp == null) {
            return null;
        }
        return DateTimeDemo.toLocalDateTime(this.lastTimestamp);
    }

    /**
     * 延迟量
     * 
     * @return
     */
    public Integer getDiffTotal() {
        if (brokerOffset != null && consumerOffset != null) {
            return brokerOffset - consumerOffset;
        }
        return null;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public String getBrokerName() {
        return brokerName;
    }

    public void setBrokerName(String brokerName) {
        this.brokerName = brokerName;
    }

    public Integer getQueueId() {
        return queueId;
    }

    public void setQueueId(Integer queueId) {
        this.queueId = queueId;
    }

    public Integer getBrokerOffset() {
        return brokerOffset;
    }

    public void setBrokerOffset(Integer brokerOffset) {
        this.brokerOffset = brokerOffset;
    }

    public Integer getConsumerOffset() {
        return consumerOffset;
    }

    public void setConsumerOffset(Integer consumerOffset) {
        this.consumerOffset = consumerOffset;
    }

    public String getClientInfo() {
        return clientInfo;
    }

    public void setClientInfo(String clientInfo) {
        this.clientInfo = clientInfo;
    }

    public Long getLastTimestamp() {
        return lastTimestamp;
    }

    public void setLastTimestamp(Long lastTimestamp) {
        this.lastTimestamp = lastTimestamp;
    }
}
